import Vue from 'vue';
import Router from 'vue-router';

/* Layout */
import Layout from '@/layout'

Vue.use(Router);
export const constantRoutes = [
    {
        path: '/redirect',
        component: Layout,
        hidden: true,
        children: [
            {
                path: '/redirect/:path(.*)',
                component: () => import('@/views/redirect/index')
            }
        ]
    },
    {
        path: '/login',
        component: () => import('@/views/login/index'),
        hidden: true
    },
    {
        path: '/auth-redirect',
        component: () => import('@/views/login/auth-redirect'),
        hidden: true
    },
    {
        path: '/404',
        component: () => import('@/views/error-page/404'),
        hidden: true
    },
    {
        path: '/401',
        component: () => import('@/views/error-page/401'),
        hidden: true
    },
    {
        path: '/phone',
        component: () => import('@/views/phone/index'),
        hidden: true
    },
    {
        path: '/indexList',
        component: () => import('@/views/phone/indexList'),
        hidden: true
    },
    {
        path: '/success',
        component: () => import('@/views/phone/success'),
        hidden: true
    },
    {
        path: '/',
        component: Layout,
        redirect: '/eventManagement/index',
    },
    {
        path: '/eventManagement',
        component: Layout,
        children: [
            {
                path: 'index',
                component: () => import('@/views/eventManagement/index'),
                name: 'EventManagement',
                meta: {title: '事件管理', icon: 'documentation', noCache: true}
            },
            {
                path: 'infoEdit/:id',
                component: () => import('@/views/eventManagement/infoEdit'),
                name: 'EventManagementDetail',
                hidden: true,
                meta: {title: '事件详情', icon: 'documentation', noCache: true}
            }
        ]
    },
    {
        path: '/systemManagement',
        component: Layout,
        meta: {title: '系统管理', icon: 'documentation', noCache: true},
        children: [
            {
                path: 'user',
                component: () => import('@/views/system/user/index'),
                name: 'userManagement',
                meta: {title: '用户管理', icon: 'documentation', noCache: true}
            }, {
                path: 'role',
                component: () => import('@/views/system/role/index'),
                name: 'roleManagement',
                meta: {title: '角色管理', icon: 'documentation', noCache: true}
            },/* {
                path: 'menu',
                component: () => import('@/views/system/menu/index'),
                name: 'menuManagement',
                meta: {title: '菜单管理', icon: 'documentation',  noCache: true}
            },*/ {
                path: 'dept',
                component: () => import('@/views/system/dept/index'),
                name: 'deptManagement',
                meta: {title: '组织机构', icon: 'documentation', noCache: true}
            }, {
                path: 'dict',
                component: () => import('@/views/system/dict/index'),
                name: 'dictManagement',
                meta: {title: '字典管理', icon: 'documentation', noCache: true}
            }, {
                path: 'data/:id',
                component: () => import('@/views/system/dict/data'),
                name: 'dictManagement',
                hidden: true,
                meta: {title: '字典类型', icon: 'documentation', noCache: true}
            }
        ]
    },
    {
        path: '/tool',
        component: Layout,
        meta: {title: '工具管理', icon: 'documentation', noCache: true},
        hidden: true,
        children: [
            {
                path: 'generator',
                component: () => import('@/views/tool/generator/index'),
                name: 'generatorManagement',
                meta: {title: '代码生成', icon: 'documentation', noCache: true}
            }, {
                path: 'preview/:tableName',
                component: () => import('@/views/tool/generator/preview'),
                name: 'previewManagement',
                hidden: true,
                meta: {title: '预览', icon: 'documentation', noCache: true}
            }, {
                path: 'config/:tableName',
                component: () => import('@/views/tool/generator/config'),
                name: 'configManagement',
                hidden: true,
                meta: {title: '配置管理', icon: 'documentation', noCache: true}
            },
        ]
    }
]
export const asyncRoutes = [
    // 404 page must be placed at the end !!!
    {path: '*', redirect: '/404', hidden: true}
]
const createRouter = () => new Router({
    mode: 'history', // require service support
    scrollBehavior: () => ({y: 0}),
    routes: constantRoutes
})
const router = createRouter()

export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
}

export default router
